<template>
  <div class="inquirerfid">
    <div class="inquirerfid-search">
      <el-input
        v-model="form.number"
        placeholder="请输入RFID"
        @keyup.enter.native="onSearch"
        clearable
      ></el-input>
      <el-button type="primary" @click="onSearch">查询</el-button>
    </div>
    <div v-if="data.factory_name">{{ data.factory_name }} ({{ sku_code }})</div>
    <el-timeline style="margin-top: 40px">
      <el-timeline-item
        v-for="(activity, index) in activities"
        :key="index"
        :timestamp="activity.timestamp"
      >
        {{ activity.content }}
      </el-timeline-item>
    </el-timeline>
  </div>
</template>

<script>
import { postCodeGetnumber } from "@/api";
export default {
  data() {
    return {
      form: {
        number: "",
      },
      data: "",
      sku_code:"",
      activities: [],
    };
  },
  activated() {},
  methods: {
    // 查询
    onSearch() {
      let obj = this.form;
      if (obj.number) {
        this.postCodeGetnumber(obj);
      } else {
        this.$mesage.warning("请输入RFID");
      }
    },
    postCodeGetnumber(number) {
      this.activities = [];
      (this.data = ""),
        postCodeGetnumber(number).then((res) => {
          console.log("rfid查询", res);
          let data = res.data;
          if(res.res){
            this.data = res.res;
          }
          if(data.sku_code){
            this.sku_code = data.sku_code
          }
         
          let arr = [];
          if (data.createtime) {
            let obj = {
              content: "生成",
              timestamp: data.createtime,
            };
            arr.push(obj);
          }
          if (data.printing_time) {
            let obj = {
              content: "打印",
              timestamp: data.printing_time,
            };
            arr.push(obj);
          }
          if (data.fa_time) {
            let obj = {
              content: "出厂",
              timestamp: data.fa_time,
            };
            arr.push(obj);
          }
          if (data.qc && data.qc.length) {
            data.qc.forEach((e) => {
              let obj = {
                content: `QC(${e.qc_user})已检 ${
                  e.status == 1 ? "合格" : "不合格"
                }`,
                timestamp: e.qc_time,
              };
              arr.push(obj);
            });
          }
          if (data.qt && data.qt.length) {
            data.qt.forEach((e) => {
              let obj = {
                content: `仓检(${e.qc_user})已检 ${
                  e.status == 1 ? "合格" : "不合格"
                }`,
                timestamp: e.qc_time,
              };
              arr.push(obj);
            });
          }
          if (data.ware_time) {
            let obj = {
              content: "入库",
              timestamp: data.ware_time,
            };
            arr.push(obj);
          }
          if (data.delivery_time) {
            let obj = {
              content: "出库",
              timestamp: data.delivery_time,
            };
            arr.push(obj);
          }
          this.activities = arr;
        });
    },
  },
};
</script>
<style lang="scss" scoped>
.inquirerfid {
  background: #ffffff;
  padding: 20px;
  &-search {
    display: flex;
    justify-content: space-between;
    padding-bottom: 20px;
    /deep/ .el-input {
      width: 90%;
    }
  }
}
</style>